package com.chia.multienty.workflow.dubbo.service.impl;

import com.chia.multienty.core.domain.bo.workflow.ProcessDeployResult;
import com.chia.multienty.core.domain.bo.workflow.ProcessStartResult;
import com.chia.multienty.core.dubbo.service.DubboWorkflowService;
import com.chia.multienty.core.parameter.workflow.*;
import com.chia.multienty.core.pojo.ProcessArg;
import com.chia.multienty.core.pojo.WorkflowProcess;
import com.chia.multienty.core.service.ProcessArgService;
import com.chia.multienty.core.service.WorkflowProcessService;
import com.chia.multienty.workflow.service.FlowableGroupService;
import com.chia.multienty.workflow.service.FlowableMembershipService;
import com.chia.multienty.workflow.service.FlowableProcessService;
import com.chia.multienty.workflow.service.FlowableUserService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.flowable.idm.api.Group;
import org.flowable.idm.api.User;

import java.util.List;
import java.util.Map;

@DubboService
@RequiredArgsConstructor
public class DubboWorkflowServiceImpl implements DubboWorkflowService {
    private final FlowableUserService flowableUserService;
    private final FlowableGroupService flowableGroupService;
    private final FlowableMembershipService flowableMembershipService;
    private final FlowableProcessService flowableProcessService;
    private final WorkflowProcessService workflowProcessService;

    private final ProcessArgService processArgService;

    @Override
    public List<ProcessArg> getProcessArgs(Long processId, List<Long> argIds) {
        return processArgService.getProcessArgs(processId, argIds);
    }

    @Override
    public void addUser(FlowableUserAddParameter parameter) {
        flowableUserService.add(parameter);
    }

    @Override
    public void deleteUser(String userId) {
        flowableUserService.delete(userId);
    }

    @Override
    public List<User> getUserList(FlowableUserSearchParameter parameter) {
        return flowableUserService.list(parameter);
    }

    @Override
    public void addGroup(FlowableGroupAddParameter parameter) {
        flowableGroupService.add(parameter);
    }

    @Override
    public void deleteGroup(FlowableGroupDeleteParameter parameter) {
        flowableGroupService.delete(parameter);
    }

    @Override
    public List<Group> getGroupList(FlowableGroupListGetParameter parameter) {
        return flowableGroupService.list(parameter);
    }

    @Override
    public void addMembership(String userId, String groupId) {
        flowableMembershipService.add(new FlowableMembershipAddParameter().setGroupId(groupId).setUserId(userId));
    }

    @Override
    public void deleteMembership(String userId, String groupId) {
        flowableMembershipService.delete(new FlowableMembershipDeleteParameter()
                .setGroupId(groupId)
                .setUserId(userId));
    }

    @Override
    public ProcessDeployResult deploy(FlowableDeployParameter parameter) {
        return flowableProcessService.deploy(parameter);
    }

    @Override
    public ProcessDeployResult redeploy(FlowableRedeployParameter parameter) {
        return flowableProcessService.redeploy(parameter);
    }

    @Override
    public void deleteDeploy(FlowableDeployDeleteParameter parameter) {
        flowableProcessService.deleteDeploy(parameter);
    }

    @Override
    public ProcessStartResult start(FlowableProcessStartParameter parameter) {
        ProcessStartResult result = flowableProcessService.start(parameter);
        return result;
    }

    @Override
    public WorkflowProcess getWorkflowProcess(WorkflowProcessDetailGetParameter parameter) {
        return workflowProcessService.getDetail(parameter);
    }

    @Override
    public List<Map<String, Object>> getTaskList(FlowableTaskListGetParameter parameter) {
        return flowableProcessService.list(parameter);
    }

    @Override
    public void examine(FlowableExamineParameter parameter) {
        flowableProcessService.examine(parameter);
    }

    @Override
    public void revoke(FlowableProcessRevokeParameter parameter) {
        flowableProcessService.revoke(parameter);
    }
}
